const query = require('../db/query')

const searchBook = async (params)=>{
    const data = {
        pageCode:params.pageCode ? params.pageCode : 1,
        pageSize:params.pageSize ? params.pageSize : 2,
        searchValue:params.searchValue ? params.searchValue : ''
    }
    const sql = `select * from bookslist where texttitle like '%${data.searchValue}%' limit ${(data.pageCode-1)*data.pageSize},${data.pageSize}`
    return query(sql)
}

const searchDoctor = async (params)=>{
    const data = {
        pageCode:params.pageCode ? params.pageCode : 1,
        pageSize:params.pageSize ? params.pageSize : 2,
        searchValue:params.searchValue ? params.searchValue : ''
    }
    const sql = `select * from doctorlist where doctorname like '%${data.searchValue}%' limit ${(data.pageCode-1)*data.pageSize},${data.pageSize}`
    return query(sql)
}

const searchSoco = async (params)=>{
    const data = {
        pageCode:params.pageCode ? params.pageCode : 1,
        pageSize:params.pageSize ? params.pageSize : 2,
        searchValue:params.searchValue ? params.searchValue : ''
    }
    const sql = `select * from soco where nosocomium like '%${data.searchValue}%' limit ${(data.pageCode-1)*data.pageSize},${data.pageSize}`
    return query(sql)
}

const searchAdmin = async (params)=>{
    const sql = `SELECT * FROM adminchildred where adminchildrenname like '%${params.searchValue}%'`
    return query(sql)
}

module.exports = {
    searchBook,
    searchDoctor,
    searchSoco,
    searchAdmin
}